package leetcode.简单;

import leetcode.entity.ListNode;
import leetcode.utils.ListNodeUtils;
import org.junit.Test;

public class leetcode876_列表的中间节点 {

    @Test
    public void test(){
        ListNode listNode = ListNodeUtils.createListNode(6);
    }


    public ListNode middleListNode(ListNode node){
        ListNode first = new ListNode(0,node);
        int listNodeLength = getListNodeLength(node);
        ListNode cur = first;
        for (int i = 0;i<listNodeLength/2+1;i++){
            cur = cur.next;
        }
        if (listNodeLength%2 == 0){
            cur = cur.next;
        }
        return cur;
    }


    public int getListNodeLength(ListNode node){
        int i = 0;
        while(node!=null){
            i++;
            node=node.next;
        }
        return i;
    }
}
